package com.qf.service.Impl;

import com.qf.dao.AccountDao;
import com.qf.pojo.Account;
import com.qf.service.AccountService;

/**
 * @ClassName AccountServiceImpl
 * @Author xiao宋
 * @Date 19:49  2022/9/28
 * @Version 1.0
 * @Description TODO
 */
public class AccountServiceImpl implements AccountService {
    AccountDao dao;

    public void setDao(AccountDao dao) {
        this.dao = dao;
    }

    public void transfer(String nameA, String nameB, int count) {

//        查钱
        Account a = dao.findByName(nameA);
        Account b = dao.findByName(nameB);

//        转钱
        a.setMoney(a.getMoney()-count);
        b.setMoney(b.getMoney()+count);

//        数据库出账
        dao.update(a);
//        System.out.println(1/0);
        dao.update(b);

    }
}
